package logic

import (
	"context"
	"fmt"
	"hui-hui/models"

	"hui-hui/hui_hui_rpc/hui_hui_rpc"
	"hui-hui/hui_hui_rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PushPlanLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPushPlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushPlanLogic {
	return &PushPlanLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PushPlanLogic) PushPlan(in *hui_hui_rpc.PushPlanRequest) (*hui_hui_rpc.PushPlanResponse, error) {
	// todo: add your logic here and delete this line
	plan := models.Plan{
		UserId: int(in.UserId),
		Title:  in.Title,
		Image:  in.Image,
		Des:    in.Des,
	}
	if models.DB.Create(&plan).Error != nil {
		return nil, fmt.Errorf("服务器繁忙")
	}
	return &hui_hui_rpc.PushPlanResponse{}, nil
}
